// pages/follow/sellfollow/sellfollow.js
var data = require("../../../testfollowdata.js");
const net = require("../../../utils/net.js");
const util = require("../../../utils/util.js");
const gd = getApp().globalData;
let posting = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:"",
    currentDate:"日期筛选",
    list: [],
    checked:false,
    curOprIndex:0,
    search_type:1,
    daydisable:true,
    day:"",
    member:"",
    page:1
  },
  callphone(e){
    var mobile = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: mobile
    })
    this.showOpr(0,false);
  },edit(e){
    var memberid = e.currentTarget.dataset.memberid
    var type = e.currentTarget.dataset.type
    console.log("edit",e);
    util.Forward("../orderedit/orderedit?id=" + memberid+"&type="+type);
    this.showOpr(0,false);
  }, moreopr(event){
    var index = event.currentTarget.dataset.id;
    console.log("moreopr:"+index);
    this.showOpr(this.data.curOprIndex,false);
    this.showOpr(index,true);

  },
  hideopr(){
    this.showOpr(0,false);
  },
  showOpr(index,isShow) {
    var l =this.data.list;
    if(isShow){
      l[index]["right"] = 0;
    }else{
      for (var i = 0; i < l.length;++i){
        if(l[i]["right"]==0){
          l[i]["right"] = -150;
        }
      }
    }
    this.setData({
      list: l,
      curOprIndex:index
    })
  },
  date(){

  },
  getData(getmore){
    if (posting) return;
    posting = true;
    var that = this;
    var member = this.data.member;
    var day = this.data.day;
    var date = this.data.currentDate == "日期筛选" ? "" : this.data.currentDate;
    var search_type = this.data.search_type;
    wx.showLoading({})
    this.setData({
      list:[]
    })
    net.request({
      url: '/FollowUpList',
      data: {
        keyword: member,
        search_day: date,
        days: day,
        shop_id: gd.shop_id,
        member_ship_id: gd.id,
        search_type: search_type
      }, success(res) {
        var dt = res.data;
        var list = !getmore ? [] : that.data.list;
        if (dt.flag) {
          if (dt.data.length > 0) {
            for (let i = 0; i < dt.data.length; ++i) {
              list.push(dt.data[i]);
            }
            that.setData({
              list: list
            })
          }
        } else {
          that.dialog.showDialog({
            msg: dt.msg
          })
        }
      }, fail(res) { },
      complete() {
        wx.hideLoading();
        posting = false;
      }
    })
  },
  query(){
    this.getData(false);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var title = "MC销售跟进";
    if (options.type==2){
      title = "MC服务跟进";
      this.setData({
        search_type: options.type
      })
    }
    wx.setNavigationBarTitle({
      title: title,
    })
    for (var i = 0; i < this.data.list;++i){
      list[i]["right"] = -120;
    }

    this.getData();
  },
  check(){
    var day = this.data.day;
    if (this.data.checked){
      day = "";
    }
    this.setData({
      day: day,
      checked:!this.data.checked,
      daydisable: this.data.checked
    })
  },
  input(e) {
    var value = e.detail.value + "";
    var key = e.currentTarget.id + "";
    this.setData({
      [key]: value,
    });
  },
  bindDateChange(e){
    console.log(e);
    this.setData({
      currentDate:e.detail.value
    })
  }, cancelDate(){
    console.log("cancelDate");
    this.setData({
      currentDate: "日期筛选"
    })
  },
  navgo(e){
    var id = e.currentTarget.dataset.mid
    var type = this.data.search_type;
    var route="";
    if(type==1){
      route = "../potent/potent?id=" + id;
    }else{
      route = "../avail/avail?id=" + id;
    } 
    console.log(e,route);
    util.Forward(route);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.dialog = this.selectComponent("#dialog");
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // this.setData({
    //   list:[]
    // })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})